From 2cf6c36cd3b087e47b306965f0698e2cd6bab6bd Mon Sep 17 00:00:00 2001 From: alexmot Date: Tue, 29 Jul 2003 15:49:07 +0000 Subject: [PATCH] 1. Fix bug with field delimiter getting overwritten by record delimiter. 2. Add field and record delimiters to bad characters by default. --- gpsbabel/xcsv.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/gpsbabel/xcsv.c b/gpsbabel/xcsv.c index 248ef58d8..259992577 100644 --- a/gpsbabel/xcsv.c +++ b/gpsbabel/xcsv.c @@ -205,6 +205,22 @@ xcsv_parse_style_line(const char *sbuff) } else xcsv_file.field_delimiter = sp; + + p = csv_stringtrim(xcsv_file.field_delimiter, " ", 0); + + /* field delimiters are always bad characters */ + if (xcsv_file.badchars) { + xcsv_file.badchars = xrealloc(xcsv_file.badchars, + strlen(xcsv_file.badchars) + + strlen(p) + 1); + } else { + xcsv_file.badchars = xcalloc(strlen(p) + 1, 1); + } + + strcat(xcsv_file.badchars, p); + + xfree(p); + } else if (ISSTOKEN(sbuff, "RECORD_DELIMITER")) { @@ -215,7 +231,23 @@ xcsv_parse_style_line(const char *sbuff) xfree(sp); } else - xcsv_file.field_delimiter = sp; + xcsv_file.record_delimiter = sp; + + p = csv_stringtrim(xcsv_file.record_delimiter, " ", 0); + + /* record delimiters are always bad characters */ + if (xcsv_file.badchars) { + xcsv_file.badchars = xrealloc(xcsv_file.badchars, + strlen(xcsv_file.badchars) + + strlen(p) + 1); + } else { + xcsv_file.badchars = xcalloc(strlen(p) + 1, 1); + } + + strcat(xcsv_file.badchars, p); + + xfree(p); + } else if (ISSTOKEN(sbuff, "DESCRIPTION")) { @@ -239,12 +271,26 @@ xcsv_parse_style_line(const char *sbuff) if (ISSTOKEN(sbuff, "BADCHARS")) { sp = csv_stringtrim(&sbuff[9], "\"", 1); cp = get_char_from_constant_table(sp); + if (cp) { - xcsv_file.badchars = xstrdup(cp); + p = xstrdup(cp); xfree(sp); } else - xcsv_file.badchars = sp; + p = sp; + + if (xcsv_file.badchars) { + xcsv_file.badchars = xrealloc(xcsv_file.badchars, + strlen(xcsv_file.badchars) + + strlen(p) + 1); + } else { + xcsv_file.badchars = xcalloc(strlen(p) + 1, 1); + } + + strcat(xcsv_file.badchars, p); + + xfree(p); + } else if (ISSTOKEN(sbuff, "PROLOGUE")) { -- 2.30.2